<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>05_生命周期(新17)</title>
</head>
<body>
    <script src="../React-js/17.0/react.development17.0.js" type="text/javascript"></script>
    <script src="../React-js/17.0/react-dom.development17.0.js" type="text/javascript"></script>
    <script src="../React-js/17.0/babel.min.js" type="text/javascript"></script>

    <div id="test"></div>
    <script type="text/babel">
        class Father extends React.Component{
            constructor(props){
                super(props)
                console.log('constructor');
                this.state = {val:1}
            }
            // 在render之后执行 可以获取更新前的DOM
            getSnapshotBeforeUpdate(props,state){
                console.log('getSnapshotBeforeUpdate');
                return 6
            }
            componentDidUpdate(perProps,perState,snap){
                // 第三个参数接收getSnapshotBeforeUpdate的返回值
                console.log('componentDidUpdate',perProps,perState,snap);
            }
            render(){
                return (
                    <div>
                        <h2>father:{this.state.val}</h2>
                        <button onClick={this.change}>改变</button>
                   </div>
                )
            }
            change = ()=>{
                this.setState({val:this.state.val+1})
            }
        }
        ReactDOM.render(<Father xx={99}/>,document.querySelector('#test'))
    </script>
</body>
</html>